package com.ruoyi.pcwl.app;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Map;

public class JsonToMapExample {
    public static void main(String[] args) throws Exception {
        String json = "{\"name\":\"John\", \"age\":30}"; // JSON字符串

        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode rootNode = objectMapper.readTree(json);
        Map<String, Object> map = objectMapper.convertValue(rootNode, new TypeReference<Map<String, Object>>() {});

        System.out.println("Converted Map:");
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }

    }
}
